﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<BA2009.Entities.Resource>>" %>
<%@ Import Namespace="MvcContrib.UI.Grid" %>
<%@ Import Namespace="MvcContrib.UI.Grid.ActionSyntax" %>


<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Index
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    
    <link href="../../media/css/jtable.css" rel="stylesheet" type="text/css" />
    <link href="../../media/css/StyleSheet.css" rel="stylesheet" type="text/css" />
    <link href="../../media/css/jquery.cluetip.css" rel="stylesheet" type="text/css" />
    <link href="../../media/css/confirm.css" rel="stylesheet" type="text/css" />
    
    <script src="../../media/js/jTable-Customize.js" type="text/javascript"></script>
    <script src="../../media/js/jquery.dimensions-1.2.js" type="text/javascript"></script>
    <script src="../../media/js/jquery.cluetip.js" type="text/javascript"></script>
    <script src="../../media/js/jquery.simplemodal.js" type="text/javascript"></script>
    
    <script type="text/javascript">
        $(document).ready(function() {

            createTable();

        }
        );
        
        
    </script>
    
    <script type="text/javascript">
        $(document).ready(function() {

            $(".actions").each(function() {
                var btn = $(this).find(".delete");

                $(this).find(".delete").click(function(e) {
                    e.preventDefault();
                    var msg = $(this).attr("title")
                    var selectedId = $(this).attr("id")

                    var selectedRow = $(this).parent().parent().parent();

                    confirm("Bạn có muốn xóa Banner " + msg + "?", function() {
                        deleteRow(selectedRow, btn, selectedId);
                    });


                });
            });
        });

        function deleteRow(row, args, id) {

            var url = "/Banners/Delete/" + id;

            $.post(url, null,
                function(data) {
                    removeRow(row, data);

                }
            , "json");

            return true;
        }

        function removeRow(row, data) {
            if (data == true) {
                row.remove();
            }
            else {
                alert("Xóa thất bại, vui lòng thử lại.");
            }
        }

        function confirm(message, callback) {
            $('#confirm').modal({
                close: false,
                overlayId: 'confirmModalOverlay',
                containerId: 'confirmModalContainer',
                onShow: function(dialog) {
                    dialog.data.find('.message').append(message);

                    // if the user clicks "yes"
                    dialog.data.find('.yes').click(function() {
                        // call the callback
                        if ($.isFunction(callback)) {
                            callback.apply();
                        }
                        // close the dialog
                        $.modal.close();
                    });
                }
            });
        }
                            
</script>
    
    <h2>Danh sách tài nguyên</h2>
    <div id="create_resource">
        <%=Html.ActionLink("Tạo mới","Create") %>
    </div>
    <div id="search_container">
        <p>
            <%Html.Grid(Model).Columns
            (
             colunm =>
             {
                 colunm.For(c => c.ResourceID).Named("ID");
                 colunm.For(c => c.Code).Named("Mã");
                 colunm.For(c => c.FileName).Named("Tên file");
                 colunm.For(c => c.NumberOfClicked).Named("Số lần được click");
                 colunm.For(c => c.Description).Named("Mô tả");
                 colunm.For(c => c.ResourceID).Named("Thao Tác").Action(resource =>
                     {%>
                        <td class="actions" id="row<%= resource.ResourceID %>">
                            <a href="/Resources/Edit/<%= resource.ResourceID %>"> <img src="../../media/images/edit.png" style="border-width: 0px;" alt="Thay đổi" class="edit" /> </a> 
                             <a href="#"> <img src="../../media/images/delete.png" style="border-width: 0px;" id="<%=resource.ResourceID %>" title="<%=resource.Code %>"  alt="Xóa" class="delete" /> </a> 
                        </td>
                     <%}
                     );
             }
            ).Render(); %>
        </p>
    </div>

</asp:Content>
